#include<iostream>
#include<malloc.h>
#include<math.h>
using namespace std;
typedef struct node
{
	struct node *left,*right;
	char data;
}BTNode;
typedef BTNode* ElementType;

BTNode* CreateBTree(char *pre,char *in,int n){
	int k;
	char *p;
	if(n <= 0) return NULL;
	
	BTNode *b = (BTNode*)malloc(sizeof(BTNode));
	b->data = *pre;
	for(p = in;p<in+n;++p)
		if(*p == *pre) break;
	k=p-in;
	b->left = CreateBTree(pre+1,in,k);
	b->right = CreateBTree(pre+k+1,p+1,n-k-1);
	return b;
}

int hight(BTNode *n)
{
	if(n){
		int lhight=hight(n->left);
		int rhight=hight(n->right);
		int m = max(lhight,rhight);
		return (m + 1);
	}else{
		return 0;
	}
	
}

int main()
{
	BTNode *temp;
	int n;
	cin>>n;
	char a[n+5],b[n+5];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	temp = CreateBTree(a,b,n);
	printf("%d\n",hight(temp));
	
	return 0;
}
